﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SlamDunk.CMS.Model
{
    /// <summary>
    /// Menus实体类（手写部分）
    /// </summary>
    public partial class Menus
    {
        #region 01.方法——转换为视图模型对象
        /// <summary>
        /// 转换为视图模型对象方法
        /// </summary>
        /// <returns>视图模型对象</returns>
        public Model.MenusView ToViewModel()
        {
            return new Model.MenusView()
            {
                Id = this.Id,
                PId = this.PId,
                MenuName = this.MenuName,
                Url = this.Url,
                IsLink = this.IsLink,
                Level = this.Level,
                Sort = this.Sort,
                Ico = this.Ico
            };
        }
        #endregion

        #region 02.方法——菜单实体转换为树形节点
        /// <summary>
        /// 菜单实体转换为树形节点方法
        /// </summary>
        /// <returns>树形节点</returns>
        public Model.TreeModel ToTreeNode()
        {
            //返回TreeModel
            return new Model.TreeModel()
            {
                id = this.Id,
                text = this.MenuName,
                state = "open",
                attributes = new { href = this.Url, isLink = this.IsLink == true ? 1 : 0 },
                @checked = false
            };
        }
        #endregion
    }
}
